
/*
 * 参数       必填  类型    值
 * scrollFlag 否   boolean false代表解除滚动锁定
 */
function wsjScrollLock(scrollFlag) {

    var _html = document.getElementsByTagName('html')[0]
    if (scrollFlag === false) {
        if (parseInt(_html.style.top) <= 0) {
            var scrollT = Math.abs(parseInt(_html.style.top))
            var obj = { "position": "", "width": "", "height": "", "overflow": "", "top": "" }
            for (var t in obj) {
                _html.style[t] = obj[t]
            }
            document.body.scrollTop = document.documentElement.scrollTop = scrollT;
        }
        return
    }
    //第一次调用时,_html.style.top为NaN
    if (!(parseInt(_html.style.top) < 0)) {
        var scrollT = __getScrollTop()
        if (__isAppearScroll()) __isShowScrollBar()
        else __isShowScrollBar(false)
        // 添加下方css,让页面无滚动条,即使得页面无法滚动
        var obj = { "position": "fixed", "width": "100%", "height": "100%" }
        for (var t in obj) {
            _html.style[t] = obj[t]
        }
        _html.style['top'] = -1 * scrollT + 'px'
    }

    /**
     * 获取窗口滚动条高度
     */
    function __getScrollTop() {
        var scrollTop = 0;
        if (document.documentElement && document.documentElement.scrollTop) {
            scrollTop = document.documentElement.scrollTop;
        }
        else if (document.body) {
            scrollTop = document.body.scrollTop;
        }
        return scrollTop;
    }

    function __isAppearScroll() {
        var isTrue = document.documentElement.offsetHeight > document.documentElement.clientHeight
        //为true代表有滚动条
        return isTrue
    }

    function __isShowScrollBar(param) {
        var _html = document.getElementsByTagName('html')[0]
        //param为false表示不要显示滚动条
        if (param === false) _html.style['overflow'] = ''
        else _html.style['overflow'] = 'scroll'
    }
}
/*
 *下方函数与上述插件无关
 *附赠一个获取scrollBar宽度的函数
 */
function getScrollbarWidth() {
    var oP = document.createElement('p'),
        styles = {
            width: '100px',
            height: '100px',
            overflowY: 'scroll'
        }, i, scrollbarWidth;
    for (i in styles) oP.style[i] = styles[i];
    document.body.appendChild(oP);
    console.log(oP.offsetWidth)
    console.info(oP.clientWidth)
    scrollbarWidth = oP.offsetWidth - oP.clientWidth;
    oP.remove();
    return scrollbarWidth;
}